<template>
	<view>
		<uni-popup ref="refusePopup" background-color="#fff" type="dialog" class="refuse_dialog">
		<uni-popup-dialog :type="msgType" cancelText="取消" confirmText="确定" title="撤销合同" @confirm="invalidContract" :before-close="true" @close="cancel">
		<view class="text_item">您确定要【撤销】合同吗？<br/>撤销合同：表示您终止本次签约，使已签署、或正在签署的文件强制失效。
		  <view style="margin-top:20rpx;font-size: 26rpx;">请填写撤销原因： <span style="color:#999999">(非必填)</span></view>
		  <uni-easyinput type="textarea" v-model="revokeReason" placeholder="请输入撤销原因"></uni-easyinput>
		  <view class="tip">温馨提示：撤回后，系统会保留原合同设置信息，可重新发起！</view>
		  </view>
		</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {invalidContract} from "@/api/ec/work/contract/contract";
	export default {
		name:"revokeDialog",
		props: {
		  id: {
			default:null,
		    type: Number,
		  },
		  // 撤回人是发起方还是接收方
		   invalidIsStarter:{
		     type: Boolean,
		   },   
		  },
		data() {
			return {
				msgType: 'warning',
				revokeReason:'', //撤回原因 
				tabIndex:'',
			};
		},
		methods:{
			open(){
				this.$refs.refusePopup.open('center')
			},
			cancel(){
				this.revokeReason = null
				this.$refs.refusePopup.close()
			},
			/** 撤销合同 */
			invalidContract() {
				// 只有发起方才能撤回 接收方没有撤回权限
				if(!this.invalidIsStarter){
				  this.$modal.msgError("无权限撤回！");
				  return false;
				}      
			  invalidContract({contractId: this.id, sealInfo: this.revokeReason}).then((response) => {
			    this.$refs.refusePopup.close()
				this.revokeReason = null
				// 刷新列表
				setTimeout(()=>{
					this.$modal.msgSuccess("作废成功！");
				},300)
				if(this.$store.getters.staffInfo.companyId == 0){
					this.tabIndex = 3
				}else{
					this.tabIndex = 4
				}
				uni.$emit('tabIndex',this.tabIndex)
				uni.switchTab({
					url:'/pages/index'
				})
			  });
			},
		},
	}
</script>

<style scoped lang="scss">
	.tip{
		font-size:22rpx;
		line-height: 30rpx;
		margin-top: 6rpx;
	}
	.text_item{color: #666666;line-height:45rpx;}
	::v-deep .uni-popup__wrapper{width: 90% !important;}
	::v-deep .uni-dialog-content{padding: 40rpx 0;}
</style>